#include "drv_timer.h"

void drv_timer6_init(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
	NVIC_InitTypeDef NVIC_InitStruct;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);//开启TIM6时钟
	TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;//时钟分割，输入才用
	TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;//选择计数方式为向上计数
	TIM_TimeBaseInitStruct.TIM_Period = 5000-1;//装载值(就是数多少次)
	TIM_TimeBaseInitStruct.TIM_Prescaler = 8400-1;//预分频值
	TIM_TimeBaseInit(TIM6,&TIM_TimeBaseInitStruct);//用上面配置的参数初始化定时器6
	TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);//指定中断源为定时器6的更新中断

	NVIC_InitStruct.NVIC_IRQChannel = TIM6_DAC_IRQn;//中断通道号
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级
	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;//响应优先级
	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;//使能中断
	NVIC_Init(&NVIC_InitStruct);
	TIM_Cmd(TIM6, ENABLE);
}

